package cc.yugu.yhdw.webserver.web.controller.security.hdw;

import cc.yugu.yhdw.common.annotation.ViewModel;
import cc.yugu.yhdw.common.constant.ConstEnum;
import cc.yugu.yhdw.common.domain.basic.User;
import cc.yugu.yhdw.common.domain.hdw.ExchangeAmountMoneyDivide;
import cc.yugu.yhdw.common.entity.json.ExtResult;
import cc.yugu.yhdw.common.entity.json.PageResult;
import cc.yugu.yhdw.common.utils.YhdwUtils;
import cc.yugu.yhdw.webserver.constant.AppConstEnum;
import cc.yugu.yhdw.webserver.service.hdw.ExchangeAmountMoneyDivideService;
import cc.yugu.yhdw.webserver.web.controller.security.SecurityController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 换电金额分配请求处理
 *
 * @Date:Created in 2018/7/13 11:44
 * @Author:
 * @Modified By: zxj 2018/7/13 11:44
 */
@Controller
@RequestMapping(value = "/security/hdw/exchange_amount_money_divide")
public class ExchangeAmountMoneyDivideController extends SecurityController {
    @Autowired
    ExchangeAmountMoneyDivideService exchangeAmountMoneyDivideService;
    /**
     * 响应结果处理（树）
     * @Param [agentId, agencyId, response]
     * @Return void
     * @Author zxj 2018/7/13
     */
    @ResponseBody
    @ViewModel(ViewModel.JSON_ARRAY)
    @RequestMapping(value = "tree.htm")
    public void tree(Integer agentId, Integer agencyId, HttpServletResponse response) throws Exception {
        // 设置响应的MIME类型
        response.setContentType(ConstEnum.ContentType.JSON.getValue());
        // 响应体处理
        exchangeAmountMoneyDivideService.tree(agentId,agencyId, response.getOutputStream());
    }
    /**
     * 页面初始化加载
     * @Param [model]
     * @Return void
     * @Author zxj 2018/7/13
     */
    @RequestMapping(value = "index.htm")
    public void index(Model model) {
        // menuCode ,  换电金额分配
        model.addAttribute(MENU_CODE_NAME, AppConstEnum.Menu.MENU_06_06.getValue());
    }
    /**
     * 表格刷新查询
     * @Param [search, request]
     * @Return cc.yugu.yhdw.common.entity.json.PageResult
     * @Author zxj 2018/7/13
     */
    @RequestMapping(value = "page.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public PageResult page(ExchangeAmountMoneyDivide search,HttpServletRequest request) {
        // 搜索查询运营商
        if (getSessionUser(request).getType() == User.Type.AGENT.getValue()) {
            search.setAgentId(getSessionUser(request).getAgentId());
        // 搜索查询代理商
        } else if (getSessionUser(request).getType() == User.Type.AGENCY.getValue()) {
            search.setAgencyId(getSessionUser(request).getAgencyId());
        }
        return PageResult.successResult(exchangeAmountMoneyDivideService.findPage(search));
    }
    /**
     * 新增（新建）(弹窗显示）
     * @Param []
     * @Return void
     * @Author zxj 2018/7/13
     */
    @ViewModel(ViewModel.INNER_PAGE)
    @RequestMapping("add.htm")
    public void add() {
    }
    /**
     * 查看（弹窗显示）
     * @Param [id, model]
     * @Return void
     * @Author zxj 2018/7/13
     */
    @RequestMapping(value = "view.htm")
    public void view(int id, Model model) {
        model.addAttribute("id", id);
    }
    /**
     * 修改（弹窗显示）
     * @Param [id, model]
     * @Return void
     * @Author zxj 2018/7/13
     */
    @ViewModel(ViewModel.INNER_PAGE)
    @RequestMapping(value = "edit.htm")
    public void edit(int id, Model model) {
        model.addAttribute("id", id);
    }

    /**
     * 修改处理
     * @Param [entity]
     * @Return cc.yugu.yhdw.common.entity.json.ExtResult
     * @Author zxj 2018/7/13
     */
    @ResponseBody
    @RequestMapping(value = "update.htm")
    @ViewModel(ViewModel.JSON)
    public ExtResult update(ExchangeAmountMoneyDivide entity) {
        return exchangeAmountMoneyDivideService.update(entity);
    }
    /**
     * 新建处理
     * @Param [entity]
     * @Return cc.yugu.yhdw.common.entity.json.ExtResult
     * @Author zxj 2018/7/13
     */
    @ResponseBody
    @ViewModel(ViewModel.JSON)
    @RequestMapping(value = "create.htm")
    public ExtResult create(ExchangeAmountMoneyDivide entity) {
        return exchangeAmountMoneyDivideService.insert(entity);
    }

    /**
     * 删除处理
     * @param id
     * @return
     */
    @RequestMapping("delete.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public ExtResult delete(int id) {
        exchangeAmountMoneyDivideService.delete(id);
        return ExtResult.successResult();
    }
    /**
     * 修改详细
     * @Param [id, model]
     * @Return void
     * @Author zxj 2018/7/13
     */
    @ViewModel(ViewModel.INNER_PAGE)
    @RequestMapping("edit_detail.htm")
    public void edit_detail(int id, Model model) {
        model.addAttribute("id", id);
    }
    /**
     * 查看详细
     * @Param [id, model]
     * @Return void
     * @Author zxj 2018/7/13
     */
    @RequestMapping("view_detail.htm")
    public void view_detail(int id, Model model) {
        model.addAttribute("id", id);
    }
    /**
     * 修改信息
     * @Param [model, id]
     * @Return void
     * @Author zxj 2018/7/13
     */
    @ViewModel(ViewModel.INNER_PAGE)
    @RequestMapping("edit_info.htm")
    public void edit_info(Model model,int id) {
        model.addAttribute("entity", exchangeAmountMoneyDivideService.find(id));
    }
    /**
     * 查看信息
     * @Param [model, id]
     * @Return void
     * @Author zxj 2018/7/13
     */
    @RequestMapping("view_info.htm")
    public void view_info(Model model,int id) {
        model.addAttribute("entity", exchangeAmountMoneyDivideService.find(id));
    }
}
